<template>
    <div class="sidebar">
        <el-menu
            class="sidebar-el-menu"
            :default-active="onRoutes"
            :collapse="collapse"
            unique-opened
            router
            background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"

        >
        <!-- background-color="#324157"
            text-color="#bfcbd9"
            active-text-color="#20a0ff"
            改变主题颜色加到router就行
                -->
            <template v-for="item in items">
                <!-- 1有子数组展示 -->
                <template v-if="item.subs">
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
                            <i :class="item.icon"></i>
                            <span slot="title">{{ item.title }}</span>
                        </template>
                            <!-- 二级渲染 -->
                        <template v-for="subItem in item.subs">
                            <el-submenu
                                v-if="subItem.subs"
                                :index="subItem.index"
                                :key="subItem.index"
                            >
                                <template slot="title">{{ subItem.title }}</template>
                                <!-- 三级导航 -->
                                <template v-for="threeItem in subItem.subs">
                                <el-submenu
                                    v-if="threeItem.subs"
                                    :index="threeItem.index"
                                    :key="threeItem.index"
                                >
                                    <template slot="title">{{ threeItem.title }}</template>
                                <el-menu-item
                                    v-for="(fourItem,i) in threeItem.subs"
                                    :key="i"
                                    :index="fourItem.index"    
                                >{{ fourItem.title }}</el-menu-item>
                                </el-submenu>
                                <el-menu-item
                                    v-else
                                    :index="threeItem.index"
                                    :key="threeItem.index"
                                >{{ threeItem.title }}</el-menu-item>
                            </template> 
                                <!-- <el-menu-item
                                    v-for="(threeItem,i) in subItem.subs"
                                    :key="i"
                                    :index="threeItem.index"    
                                >{{ threeItem.title }}</el-menu-item> -->
                            </el-submenu>
                            <el-menu-item
                                v-else
                                :index="subItem.index"
                                :key="subItem.index"
                            >{{ subItem.title }}</el-menu-item>
                        </template>
                    </el-submenu>
                </template>
                <!-- 1 items里没有数组进行渲染 -->
                <template v-else>
                    <el-menu-item :index="item.index" :key="item.index">
                        <i :class="item.icon"></i>
                        <span slot="title">{{ item.title }}</span>
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
import bus from '../common/bus';
export default {
    data() {
        return {
            collapse: false,
            items: [
                {
                    icon: 'el-icon-lx-home',
                    index: 'dashboard',
                    title: '系统首页'
                },
                {
                    icon: 'el-icon-lx-calendar',
                    index: 'table',
                    title: '活动管理',
                    subs: [
                        {
                            index: 'table',
                            title: '活动列表',
                        } ,
                        {
                            index: '1',
                            title: '任务列表'
                        },
                        {
                            index: '2',
                            title: '问卷列表'
                        },
                        {
                            index: 'createdActive',
                            title: '制定活动'
                        },
                        {
                            index: 'activityReport',
                            title: '活动报表'
                        }




                        ]

                },
                // {
                //     icon: 'el-icon-shopping-bag-1',
                //     index: '3',
                //     title: '门店管理',
                //     subs: [
                //         {
                //             index: 'storeList',
                //             title: '门店列表'
                //         }
                //     ]
                // },
                {
                    icon: 'el-icon-lx-shop',
                    index: 'Restaurant',
                    title: '餐城管理',
                    subs: [
                        {
                            index: 'category',
                            title: '分类管理'
                        },
                        {
                            index: 'management',
                            title: '商品管理'
                        },
                        {
                            index: 'swiper',
                            title: '轮播图管理'
                        },
                        {
                            index: 'recommendation',
                            title: '商品推荐'
                        }
                    ]
                },
                {
                    icon: 'el-icon-trophy',
                    index: 'brandManagement',
                    title: '渠道管理',
                    subs: [
                        {
                            index: 'brandManagement',
                            title: '品牌管理',  
                        },
                        {
                            index: 'areaManagement',
                            title: '区域管理',
                        // subs: [
                        // {
                        //     index: 'areaManagement',
                        //     title: '区域管理',  
                        // },
                        // {
                        //     index: 'storeManagement',
                        //     title: '门店管理',
                        // subs: [ 
                        // {
                        //     index: 'storeManagement',
                        //     title: '门店管理'
                        // }
                        //     ]  
                        // }
                        //     ]

                        },
                        {
                            index: 'storeManagement',
                            title: '门店管理'

                        }
                    ]
                },
                {
                    icon: 'el-icon-lx-emoji',
                    index: 'noviceGuide',
                    title: '新手指引步骤'
                },
                {
                    icon: 'el-icon-pie-chart',
                    index: 'editor',
                    title: '财务报表'
                },
                {
                    icon: 'el-icon-lx-global',
                    index: 'i18n',
                    title: '国际化功能'
                },
                {
                    icon: 'el-icon-lx-warn',
                    index: '7',
                    title: '错误处理',
                    subs: [
                        {
                            index: 'permission',
                            title: '权限测试'
                        },
                        {
                            index: '404',
                            title: '404页面'
                        }
                    ]
                },
                                {
                    icon: 'el-icon-setting',
                    index: 'authority',
                    title: '系统管理',
                    subs:[
                        {
                            index: 'userlist',
                            title: '用户列表'
                        },
                        {
                            index: 'roleslist',
                            title: '角色列表'
                        },
                        {
                            index: 'menulist',
                            title: '菜单列表'
                        }
                        // {
                        //     index: 'resourceslist',
                        //     title: '资源列表'
                        // }

                    ]
                }

            ]
        };
    },
    computed: {
        onRoutes() {
            return this.$route.path.replace('/', '');
        }
    },
    created() {
        // 通过 Event Bus 进行组件间通信，来折叠侧边栏
        bus.$on('collapse', msg => {
            this.collapse = msg;
            bus.$emit('collapse-content', msg);
        });
    }
};
</script>

<style scoped>
.sidebar {
    display: block;
    position: absolute;
    left: 0;
    top: 70px;
    bottom: 0;
    overflow-y: scroll;
}
.sidebar::-webkit-scrollbar {
    width: 0;
}
.sidebar-el-menu:not(.el-menu--collapse) {
    width: 250px;
}
.sidebar > ul {
    height: 100%;
}
</style>
